package com.briup.es.service.impl;


import com.briup.es.domain.bean.OrderItem;
import com.briup.es.domain.bean.Shopcar;
import com.briup.es.domain.vo.OrderItemVO;
import com.briup.es.mapper.OrderItemMapper;
import com.briup.es.service.OrderItemService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@RequiredArgsConstructor
public class OrderItemServiceImpl implements OrderItemService {

    private final OrderItemMapper orderItemMapper;

    @Override
    @Transactional
    public void addOrderItems(String orderId, List<Shopcar> shopcars) {
        // 将shopcars集合内容，转换成OrderItem内容集合
        List<OrderItem> orderItems = shopcars.stream()
                .map(shopcar ->
                        OrderItem.builder().orderId(orderId).bookId(shopcar.getBookId())
                                .num(shopcar.getNum()).build())
                .toList();

        // 批量添加订单项数据
        orderItemMapper.batchAddOrderItem(orderItems);
    }
}
